import { createRouter, createWebHashHistory, RouteRecordRaw, createWebHistory } from "vue-router"

const Home = () => import("@/view/Home/Home.vue")
const Singer = () => import("@/view/Singer/Singer.vue")
const Song = () => import("@/view/Song/Song.vue")
const SingerDetail = () => import("@/view/SingerDetail/SingerDetail.vue")
const SongDetail = () => import("@/view/SongDetail/SongDetail.vue")
const LyricDetail = () => import("@/view/LyricDetail/LyricDetail.vue")
const Search = () => import("@/view/Search/Search.vue")
const Login = () => import("@/view/Login/Login.vue")
const Test = () => import("@/view/Test.vue")
const MainContener = () => import("@/layout/MainContener.vue")


const routes: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: "/login",

  },
  {
    path: "/login",
    component: Login,
    meta: {
      title: "登录"
    }
  },
  {
    path: "/test",
    component: Test,
    meta: {
      title: "测试"
    }
  },
  {
    path: "/login/:isLogin",
    component: Login,
    meta: {
      title: "登录"
    }
  },
  {
    path: "/main",
    component: MainContener,
    children: [
      {
        path: "/main",
        redirect: "/main/home"
      },
      {
        path: "/main/home",
        component: Home,
        meta: {
          title: "首页"
        }
      },
      {
        path: "/main/singer",
        component: Singer,
        meta: {
          title: "歌手"
        }

      },
      {
        path: "/main/song",
        component: Song,
        meta: {
          title: "歌单"
        }
      },
      {
        path: "/main/lyric-detail",
        component: LyricDetail,
        meta: {
          title: "歌词"
        }
      },
      {
        path: "/main/song-detail",
        component: SongDetail,
        meta: {
          title: "歌单"
        }
      },
      {
        path: "/main/singer-detail",
        component: SingerDetail,
        meta: {
          keepAlive: true,
          title: "歌手"
        }
      },
      {
        path: "/main/search/:word",
        component: Search,
        meta: {
          title: "搜索"
        }
      }
    ]
  }

]

export const router = createRouter({
  history: createWebHistory(),
  routes,
})
// 全局路由守卫
router.beforeEach((to: any, _, next) => {
  document.title = to.meta?.title ?? "音乐"
  next()
})

